package com.link.base.base.wechat.controller;

import com.link.base.base.wechat.model.Messageresult;
import com.link.base.base.wechat.service.MessageresultService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.*;

/**
 * 消息定时发送
 *
 * @author lujiang
 * @date 2018-05
 */
@Controller
@RequestMapping("/link/messageresult")
public class MessageresultController extends BasicController<Messageresult> {
    @Resource
    private MessageresultService messageresultService;

    @Override
    public BasicService<Messageresult> getBasicService() throws Exception {
        return messageresultService;
    }

    /**
     * 即刻发送
     *
     * @author lujiang
     * @date 2018-05
     * @param list 消息list
     * @return
     */
    @RequestMapping(value = "nowsend", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json")
    @ResponseBody
    public Map<String, Object> nowSend(@RequestBody List<Messageresult> list) {
        Map<String, Object> map = new HashMap<>(16);
        try {
            map = messageresultService.nowSend(list);
            map.put("success",true);
        } catch (Exception e) {
            map.put("success",false);
            map.put("msg",e.getMessage());
            LCLogger.withException(e);
        }
        return map;
    }
}
